package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端-订单相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;
    /**
     * 管理端-订单分页条件查询
     * @param ordersPageQueryDTO
     * @return
     */
    @ApiOperation("订单分页条件查询")
    @GetMapping("/conditionSearch")
    public Result<PageResult> PageOrder(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单分页查询条件---> {}",ordersPageQueryDTO);
        PageResult pageResult = orderService.PageOrder(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据订单id查看订单详情
     * @param id
     * @return
     */
    @ApiOperation("根据订单id查看订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderDetailById(@PathVariable("id") Long id){
        log.info("查看订单详情功能===>当前订单id--->{}",id);
        OrderVO orderVO = orderService.getOrderDetailById(id);
        return Result.success(orderVO);
    }


    /**
     * 获取各个状态订单数量
     * @return
     */
    @ApiOperation("获取各个状态订单数量")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getOrderCount(){
        OrderStatisticsVO orderStatisticsVO = orderService.getOrderCount();
        return Result.success(orderStatisticsVO);
    }


    /**
     * 接单
     * @param
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单功能===>订单id--->{}",ordersConfirmDTO.getId());
        orderService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }


    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单功能===>订单id--->{}",ordersRejectionDTO.getId());
        orderService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }


    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单功能===>订单id--->{}",ordersCancelDTO.getId());
        orderService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }


    /**
     * 派送订单
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable("id") Long id){
        log.info("派送订单功能===>订单id--->{}",id);
        orderService.deliveryOrder(id);
        return Result.success();
    }


    /**
     * 完成订单
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable("id") Long id){
        log.info("完成订单功能===>订单id--->{}",id);
        orderService.completeOrder(id);
        return Result.success();
    }
}
